<template>
	<div>
		<Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
		    <FormItem label="姓名" prop="USER_NAME">
		        <Input v-model="formValidate.USER_NAME"  readonly placeholder="请输入您的真实姓名"></Input>
		    </FormItem>
			
			<FormItem label="所在院校" prop="college">
			    <Input v-model="formValidate.college" readonly ></Input>
			</FormItem>
			
			<FormItem label="所在专业" prop="major">
			    <Input v-model="formValidate.major" readonly ></Input>
			</FormItem>
			
			<FormItem label="所在班级" prop="class">
			    <Input v-model="formValidate.class" readonly ></Input>
			</FormItem>
			
			
		    <FormItem label="学号" prop="student_number">
		        <Input v-model="formValidate.student_number" readonly placeholder="请输入您的学号"></Input>
		    </FormItem>
			<FormItem label="手机号" prop="telphone">
			    <Input v-model="formValidate.telphone" readonly placeholder="请输入您的手机号"></Input>
			</FormItem>
		    <FormItem label="身份证号" prop="id_card">
		        <Input v-model="formValidate.id_card" readonly placeholder="请输入您的身份证号"></Input>
		    </FormItem>
		    <FormItem label="籍贯" prop="native_place">
		        <Input v-model="formValidate.native_place" readonly placeholder="请输入籍贯"></Input>
		    </FormItem>
		    <FormItem label="现租住地址" prop="now_place">
		        <Input v-model="formValidate.now_place" readonly placeholder="请输入现居住地址"></Input>
		    </FormItem>
		    
		    
		</Form>
		
	</div>
</template>

<script>
	import {saveInfo, userInfoLogind, userInfoLogindByActivated} from '@/api/lky/lkyStudent'
	import {createFormObj, createModelObj, getToken} from '@/libs/util'
	import {queryAll} from '@/api/lky/lkyCollege'
	import {queryAllM} from '@/api/lky/lkyMajor'
	import {queryFindClassByMid, queryFindClassMajorCollegeListByTid} from '@/api/lky/lkyClass'
	
	export default {
	    data () {
	        return {
				coid: '',
				mid: '',
				student_number:'',
				collegeList: [],
				majorList: [],
				classList: [],
				   //已选中的班级
				// 存放老师id，班级ids
				userInfo: {
					ID:''
				},
				formTeacherClass: {
				  id: ''
				},
	            formValidate: {
	                USER_NAME: '',
					sex:'',
	                telphone: '',
	                student_number: '',
	                id_card: '',
	                native_place: '',
					now_place:'',
					c_id: '' ,
					class: '',
					college:'',
					major:''
	            },
				rePassword: {
					REPASSWD: ''
				},
	            ruleValidate: {
	                USER_NAME: [
	                    { required: false, message: '名字不能为空', trigger: 'blur' }
	                ],
	                telphone: [
	                    { required: false, message: '手机号不能为空', trigger: 'blur' },
	                ],
	                student_number: [
	                    { required: false, message: '学号不能为空', trigger: 'blur' }
	                ],
	                id_card: [
	                    { required: false, message: '身份证号不能为空', trigger: 'blur' }
	                ],
					native_place: [
					    { required: false, message: '籍贯不能为空', trigger: 'blur' }
					],
					now_place: [
					    { required: false, message: '现租住地址不能为空', trigger: 'blur' }
					],
					c_id: [
					    { required: false, message: '必须选择班级', trigger: 'blur' }
					]
	            }
	        }
	    },
		mounted:function(){
		      this.user_info();//需要触发的函数
		    },
	    methods: {
			//获取当前登陆用户的信息
			user_info(){
				
				this.userInfo.ID=getToken();
				
				
				userInfoLogind(Object.assign({}, createModelObj(this.userInfo, 'user'))).then(
				  res => {
				    if (res) {
					  this.formValidate.USER_NAME=res.data[0].USER_NAME
					  this.formValidate.telphone=res.data[0].telphone
					  this.formValidate.student_number=res.data[0].USER_CODE
					  this.student_number=res.data[0].USER_CODE
					  console.log(this.student_number)
					  userInfoLogindByActivated(Object.assign({ student_number: this.student_number})).then(res => {
					  		this.formValidate.native_place=res.list[0].native_place
							this.formValidate.now_place=res.list[0].now_place
							this.formValidate.class=res.list[0].name
							this.formValidate.college=res.list[0].college
							this.formValidate.major=res.list[0].major
					  	}
					  )
					  this.formValidate.id_card=res.data[0].id_card
				    }
				  }
				)
				
				
				
				
			},
			onOpenChangeCollege () {
			    queryAll().then(res => {
			      this.collegeList = res.data
			    })
			  },
			  onOpenChangeMajor (coid) {
			    queryAllM({'coid': this.coid}).then(res => {
			      this.majorList = JSON.parse(JSON.stringify(res.data))
			    })
			  },
			  onOpenFindClassByMid (mid) {
			    console.log(this.mid)
			    queryFindClassByMid({'mid': this.mid}).then(res => {
			      this.classList = JSON.parse(JSON.stringify(res.data))
			    })
			  },
			  // 查询班级列表
			  queryFindClassMajorCollegeListByTid (tid) {
			    queryFindClassMajorCollegeListByTid({'tid': this.formTeacherClass.id}).then(res => {
			      this.classTeacherList = JSON.parse(JSON.stringify(res.data))
			    })
			  },
			  handleSubmit (name) {
			      this.$refs[name].validate((valid) => {
			  		saveInfo(Object.assign({}, createModelObj(this.formValidate, 'student'))).then(
			  		  res => {
			  		    if (res) {
			  		      this.$emit('addRow', res.row)
			  		      this.$emit('input', false)
			  		      this.handleReset(name)
			  		    }
			  		  }
			  		)
			      })
			  },
			  handleReset (name) {
			      this.$refs[name].resetFields();
			  }
			},
			watch: {
			  value: function (val, oldVal) {
			    this.$refs.formTeacherClass.resetFields()
			    // console.log("22===========")
			    // console.log(this.formTeacherClass)
			    coverFormProps(this.formTeacherClass, this.lkyTeacher)
			    // console.log("333====")
			    // console.log(this.lkyTeacher)
			    // console.log(this.formTeacherClass)
			  },
			  // 获取学院id
			  lkyTeacher(n){
			    if(n!=null){
			      // console.log("n========n")
			      // console.log(n)
			      // this.coid = n.id2
			      // this.formLkyClass.mid = n.mid
			      // this.onOpenChangeMajor()
			    }
			  }
			}
	    }
	
	

	
</script>

<style>
</style>
